﻿using DAEProde.Tasks;
using System;
using DAEProde.Domain;
using SharpLite.Domain.DataInterfaces;
using System.Collections.Generic;
using NUnit.Framework;

namespace DAEProde.Tests.Tasks
{    
    /// <summary>
    ///This is a test class for TicketCudTasksTest and is intended
    ///to contain all TicketCudTasksTest Unit Tests
    ///</summary>
    [TestFixture]
    [Category("Tasks Tests")]
    public class TicketCudTasksTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for TicketCudTasks Constructor
        ///</summary>
        [Test]
        public void TicketCudTasksConstructorTest()
        {
            IRepository<Ticket> ticketRepository = new Moq.Mock<IRepository<Ticket>>().Object;

            TicketCudTasks target = new TicketCudTasks(ticketRepository);

            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for TransferFormValuesTo
        ///</summary>
        [Test]
        public void TransferFormValuesToTest()
        {
            IRepository<Ticket> ticketRepository = new Moq.Mock<IRepository<Ticket>>().Object;

            TicketCudTasks_Accessor target = new TicketCudTasks_Accessor(ticketRepository);

            Ticket toUpdate = new Ticket { MatchDateScore = 0 };
            toUpdate.Predictions.Add(new Prediction { Will = "S", Ticket = toUpdate });

            Ticket fromForm = new Ticket { MatchDateScore = 1 };
            fromForm.Predictions.Add(new Prediction { Will = "L", Ticket = toUpdate });

            target.TransferFormValuesTo(toUpdate, fromForm);

            Assert.AreEqual(toUpdate.MatchDateScore, fromForm.MatchDateScore);
            var e = fromForm.Predictions.GetEnumerator();
            var e2 = toUpdate.Predictions.GetEnumerator();

            while (e.MoveNext())
            {
                e2.MoveNext();
                Assert.AreEqual(e.Current, e2.Current);
            }
        }
    }
}
